package com.lanyan.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;
        import com.lanyan.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.lanyan.common.utils.StringUtils;
import com.lanyan.system.mapper.SettingMapper;
import com.lanyan.system.domain.Setting;
import com.lanyan.system.domain.vo.SettingVo;
import com.lanyan.system.service.ISettingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 设置Service业务层处理
 *
 * @author lanyan
 * @date 2024-11-26
 */
@Service
public class SettingServiceImpl  extends ServiceImpl<SettingMapper,Setting> implements ISettingService

{
    @Autowired
    private SettingMapper settingMapper;

    /**
     * 查询设置
     *
     * @param settingId 设置主键
     * @return 设置
     */
    @Override
    public Setting selectSettingBySettingId(Long settingId)
    {
        return this.getById(settingId);
    }

    /**
     * 查询设置Vo列表
     *
     * @param setting 设置
     * @return 设置
     */
    @Override
    public List<SettingVo> selectSettingVoList(Setting setting)
    {
        return selectSettingList(setting)
                .stream()
                .map(x -> (SettingVo)x)
                .collect(Collectors.toList());
    }
    /**
     * 查询设置列表
     *
     * @param setting 设置
     * @return 设置
     */
    @Override
    public List<Setting> selectSettingList(Setting setting)
    {
        LambdaQueryChainWrapper<Setting> wrapper = this.lambdaQuery().eq(Setting::getDelFlag,"0");
        if (StringUtils.isNotEmpty(setting.getGroupKey())) {
            wrapper.eq(Setting::getGroupKey, setting.getGroupKey());
        }
        if (StringUtils.isNotEmpty(setting.getGroupName())) {
            wrapper.like(Setting::getGroupName, setting.getGroupName());
        }
        if (StringUtils.isNotEmpty(setting.getValueKey())) {
            wrapper.eq(Setting::getValueKey, setting.getValueKey());
        }
        if (StringUtils.isNotEmpty(setting.getValueName())) {
            wrapper.like(Setting::getValueName, setting.getValueName());
        }
        if (StringUtils.isNotEmpty(setting.getValue())) {
            wrapper.eq(Setting::getValue, setting.getValue());
        }
        if (setting.getGroupSort() != null) {
            wrapper.eq(Setting::getGroupSort, setting.getGroupSort());
        }
        if (setting.getValueSort() != null) {
            wrapper.eq(Setting::getValueSort, setting.getValueSort());
        }
        if (StringUtils.isNotEmpty(setting.getType())) {
            wrapper.eq(Setting::getType, setting.getType());
        }
        if (StringUtils.isNotEmpty(setting.getSelectValue())) {
            wrapper.eq(Setting::getSelectValue, setting.getSelectValue());
        }
        return wrapper.list();
    }

        /**
         * 新增设置
         *
         * @param setting 设置
         * @return 结果
         */
    @Override
        public boolean insertSetting(Setting setting)
        {
                    setting.setCreateTime(DateUtils.getNowDate());
                return this.save(setting);
        }

        /**
         * 修改设置
         *
         * @param setting 设置
         * @return 结果
         */
    @Override
        public boolean updateSetting(Setting setting)
        {
                    setting.setUpdateTime(DateUtils.getNowDate());
            return this.updateById(setting);
        }

        /**
         * 批量删除设置
         *
         * @param settingIds 需要删除的设置主键
         * @return 结果
         */
    @Override
        public boolean deleteSettingBySettingIds(Long[] settingIds)
        {
            return this.lambdaUpdate().set(Setting::getDelFlag,"1").in(Setting::getSettingId,settingIds).update();
        }

        /**
         * 删除设置信息
         *
         * @param settingId 设置主键
         * @return 结果
         */
    @Override
        public boolean deleteSettingBySettingId(Long settingId)
        {
            return this.lambdaUpdate().set(Setting::getDelFlag,"1").eq(Setting::getSettingId,settingId).update();
        }

    @Override
    public List<Setting> getGroup() {
        return settingMapper.getGroup();
    }
}
